package com.mgface.mrmdb.reids;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

public class RedisTemplateTest {

	public static void main(String[] args) throws InterruptedException {
		ApplicationContext context = new ClassPathXmlApplicationContext("classpath*:spring-redis.xml");
		RedisTemplate template = context.getBean("redisTemplate", RedisTemplate.class);
		ListOperations lop = template.opsForList();
		RedisSerializer<String> serial = new StringRedisSerializer();
		template.setKeySerializer(serial);
		template.setValueSerializer(serial);
		lop.leftPush("spring", "aaa");
		lop.leftPush("spring", "bbb");
		System.out.println(lop.size("spring"));
//		Set<String> sentinels = new HashSet<>();
//		sentinels.add(new HostAndPort("192.168.244.130", 9100).toString());
//		sentinels.add(new HostAndPort("192.168.244.130", 9101).toString());
//		sentinels.add(new HostAndPort("192.168.244.130", 9102).toString());
//
//		JedisSentinelPool sentinelsPool = new JedisSentinelPool("mymaster",
//				sentinels);
//		System.out.println("current Host:"
//				+ sentinelsPool.getCurrentHostMaster());
//		Jedis jedis = sentinelsPool.getResource();
//		String data = jedis.get("a");
//		if (data == null) {
//			jedis.set("a", "aaa");
//		}
//		Thread.sleep(5000);
//		System.out.println(jedis.get("a"));
	}

}
